<template>
  <el-dialog
    title="题目预览"
    :visible="showPreview"
    width="900px"
    :before-close="handleClose"
  >
    <el-row type="flex">
      <el-col :span="6">【题型】：{{questionInfo.questionType|qt}}</el-col>
      <el-col :span="6">【编号】：{{questionInfo.id}}</el-col>
      <el-col :span="6">【难度】：{{questionInfo.difficulty|df}}</el-col>
      <el-col :span="6">【标签】：{{questionInfo.tags}}</el-col>
    </el-row>
    <el-row type="flex" style="margin-top:10px">
      <el-col :span="6">【学科】：{{questionInfo.subjectName}}</el-col>
      <el-col :span="6">【目录】：{{questionInfo.directoryName}}</el-col>
      <el-col :span="6">【方向】：{{questionInfo.direction}}</el-col>
    </el-row>
    <hr />
    【题干】：<div v-html="questionInfo.question" style="color:blue"></div>
      <div v-if="questionInfo.questionType!=='3'">
        <div style="padding-bottom:5px">{{questionInfo.questionType|qt}} 选项：（以下选中的选项为正确答案）</div>
        <div v-for="item in questionInfo.options" :key="item.code" style="padding:8px 0">
          <el-radio v-if="questionInfo.questionType==='1'" :value="item.isRight" :label="1">{{item.title}}</el-radio>
          <el-checkbox v-if="questionInfo.questionType==='2'" :value="item.isRight?true:false" >{{item.title}}</el-checkbox>
        </div>
      </div>
    <hr />
    【参考答案】：<el-button type="danger" size="small" @click="preivewVideo()">视频答案预览</el-button>
      <div class="video" v-show="play">
        <video ref="video" :src="questionInfo.videoURL" controls></video>
      </div>
    <hr />
    【答案解析】：<div style="display:inline-block" v-html="questionInfo.answer"></div>
    <hr />
    【题目备注】：{{questionInfo.remarks}}
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleClose">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { difficulty, questionType } from '@/api/hmmm/constants.js'

export default {
  props: {
    showPreview: {
      type: Boolean,
      default: false
    },
    questionInfo: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      play: false
    }
  },

  filters: {
    df (data) {
      if (data) return difficulty.find((item) => item.value === +data).label
      // console.log(diff, 123)
    },
    qt (data) {
      if (data) return questionType.find((item) => item.value === +data).label
    }
  },
  methods: {
    handleClose () {
      this.close()
      this.$emit('update:showPreview', false)
    },
    preivewVideo () {
      this.play = true
      this.$refs.video.play()
    },
    close () {
      this.play = false
      this.$refs.video.pause()
    }
  }
}
</script>

<style scoped lang="scss">
.questions-preview{
  .el-col{
    padding: 10px 0;
  }
}
.video{
  width: 400px;
  height: 300px;
  video {
    width: 100%;
    height: 100%;
  }
}</style>
